var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
o.AdViewEm = void 0;
var a,
    i,
    n = t("AdView");
(function (t) {
    t[(t.banner = 1)] = "banner";
    t[(t.rewardVedio = 2)] = "rewardVedio";
    t[(t.interstitial = 3)] = "interstitial";
    t[(t.native = 4)] = "native";
    t[(t.custom = 5)] = "custom";
    t[(t.portal = 6)] = "portal";
})((a = o.AdViewEm || (o.AdViewEm = {})));
(function (t) {
    t[(t.receive = 0)] = "receive";
})(i || (i = {}));
var r = (function () {
    function t() {
        this.curAdCache = {};
        this.isViewAding = {};
        this.viewAdCount = {};
        this.adWait = {};
        this.haveLastTime = {};
        this.adSuccess = {};
        this.adObj = {};
        this.onceCallBack = {};
        this.devId = "";
        this.idObj = {};
        this.rewardAd = null;
        this.nativeAd = null;
        this.nativeAdData = null;
        this.nativeAdId = null;
        this.firstNativeAd = !1;
        this.lastNativeTime = 0;
        this.customAd = null;
        this.firstCustomAd = !1;
        this.lastCustomTime = 0;
        this.customConfig = null;
        this.portalAd = null;
        this.firstPortalAd = !1;
        this.lastPortalTime = 0;
        this.lastTime = 0;
        this.firstReceiveAd = !1;
    }
    t.prototype.getAdData = function (t, e, o, i, r, s) {
        var c = this;
        console.log("----------------- 当前广告模式Oppo");
        this.haveLastTime[a.interstitial] = Date.now();
        var p = this;
        this.getReceive = function (t) {
            console.log("AdViewAndroid -------------stalkooo------ 激励视频回调" + t);
            p.rewardCallBack(t);
        };
        this.loadReceive = function (t) {
            c.adSuccess[a.rewardVedio] = t;
        };
        this.callDevId = function (t) {
            if ("" != t) {
                c.devId = t;
                n.default.devId = c.devId;
            }
        };
        cc.AndroidAdverting = this;
        this.idObj[a.banner] = t;
        this.idObj[a.rewardVedio] = e;
        this.idObj[a.interstitial] = o;
        this.idObj[a.native] = i;
        this.idObj[a.custom] = r;
        this.idObj[a.portal] = s;
        this.curAdCache[a.banner] = {
            show: this.showBannerAd.bind(this),
            hide: this.hideBannerAd.bind(this),
            preLoad: this.preLoadBannerAd.bind(this),
            destory: this.destoryBannerAd.bind(this)
        };
        this.curAdCache[a.rewardVedio] = {
            show: this.showRewarVediodAd.bind(this),
            hide: this.hideRewarVediodAd.bind(this),
            preLoad: this.preLoadRewarVediodAd.bind(this),
            destory: this.destoryRewarVediodAd.bind(this),
            isCanPlay: this.canPlayReward.bind(this)
        };
        this.curAdCache[a.interstitial] = {
            show: this.showInterstitial.bind(this),
            hide: this.hideInterstitial.bind(this),
            preLoad: this.preLoadInterstitial.bind(this),
            destory: this.destoryInterstitial.bind(this)
        };
        this.curAdCache[a.native] = {
            show: this.showNativeAd.bind(this),
            hide: this.hideNativeAd.bind(this),
            preLoad: this.preLoadNativeAd.bind(this),
            destory: this.destroyNativeAd.bind(this)
        };
        this.curAdCache[a.custom] = {
            show: this.showCustomAd.bind(this),
            hide: this.hideCustomAd.bind(this),
            preLoad: this.preLoadCustomAd.bind(this),
            destory: this.destroyCustomAd.bind(this),
            setConfig: this.setCustomConfig.bind(this)
        };
        this.curAdCache[a.portal] = {
            show: this.showPortalAd.bind(this),
            preLoad: this.preLoadPortalAd.bind(this),
            destory: this.destroyPortalAd.bind(this)
        };
        setTimeout(function () {
            c.idObj[a.rewardVedio] && c.preLoadRewarVediodAd();
            c.idObj[a.portal] && c.preLoadPortalAd();
        }, 5e3);
        return this.curAdCache;
    };
    t.prototype.showBannerAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.doShowBanner = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.showInterstitial = function (t) {
        void 0 === t && (t = null);
        return !0;
    };
    t.prototype.hideBannerAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.hideRewarVediodAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.hideInterstitial = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.preLoadBannerAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.getObjCount = function (t, e) {
        return t[e] ? t[e] : 0;
    };
    t.prototype.rewardCallBack = function (t) {
        console.log("单次回调----------");
        console.log(this.onceCallBack[a.rewardVedio]);
        this.onceCallBack[a.rewardVedio] && this.onceCallBack[a.rewardVedio] && this.onceCallBack[a.rewardVedio](t);
        this.onceCallBack[a.rewardVedio] = null;
    };
    t.prototype.canPlayReward = function () {
        return !!this.adSuccess[a.rewardVedio];
    };
    t.prototype.preLoadRewarVediodAd = function (t) {
        void 0 === t && (t = null);
        console.log("预加载激励");
        if (Date.now() - this.lastTime > 5e3) {
            this.lastTime = Date.now();
            this.firstReceiveAd = !0;
            console.log("创建一个激励视频");
            this.createVideoAd();
            this.rewardAd.load();
        }
    };
    t.prototype.showRewarVediodAd = function (t) {
        void 0 === t && (t = null);
        console.log("开始播放激励视频");
        this.onceCallBack[a.rewardVedio] = t;
        if (null != this.rewardAd && this.adSuccess[a.rewardVedio]) this.rewardAd.show();
        else {
            console.log("暂时没有广告了");
            this.rewardCallBack && this.rewardCallBack(!0);
            this.createVideoAd();
        }
        this.viewAdCount[a.rewardVedio] = this.getObjCount(this.viewAdCount, a.rewardVedio) + 1;
    };
    t.prototype.preLoadNativeAd = function (t) {
        void 0 === t && (t = null);
        console.log("预加载原生广告");
        if (Date.now() - this.lastNativeTime > 5e3) {
            this.lastNativeTime = Date.now();
            this.firstNativeAd = !0;
            console.log("创建一个原生广告");
            this.createANativeAd();
        }
    };
    t.prototype.showNativeAd = function (t) {
        void 0 === t && (t = null);
        this.onceCallBack[a.native] = t;
        if (null != this.nativeAd && this.adSuccess[a.native]) {
            console.log("展示原生");
            this.nativeAd.reportAdShow({adId: this.nativeAdId});
        } else console.log("暂时没有广告了");
        this.viewAdCount[a.native] = this.getObjCount(this.viewAdCount, a.native) + 1;
    };
    t.prototype.hideNativeAd = function () {};
    t.prototype.destroyNativeAd = function () {};
    t.prototype.setCustomConfig = function (t) {
        this.customConfig = t;
    };
    t.prototype.preLoadCustomAd = function () {
        if (Date.now() - this.lastCustomTime > 5e3) {
            this.lastCustomTime = Date.now();
            this.firstCustomAd = !0;
            console.log("创建一个原生模板广告");
            this.createNewCustomAd();
        }
    };
    t.prototype.destroyCustomAd = function () {
        null != this.customAd && this.customAd.destroy();
    };
    t.prototype.showCustomAd = function () {
        var t = this;
        if (null != this.customAd)
            this.customAd
                .show()
                .then(function () {
                    console.log(t.idObj[a.custom], "show success");
                })
                .catch(function (e) {
                    console.log(t.idObj[a.custom], "show fail with:" + e.errCode + "," + e.errMsg);
                });
        else {
            console.log("没展示下广告");
            this.createNewCustomAd();
        }
    };
    t.prototype.hideCustomAd = function () {
        null != this.customAd && this.customAd.hide();
    };
    t.prototype.doShowInterstitial = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.preLoadInterstitial = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.destoryBannerAd = function () {};
    t.prototype.destoryRewarVediodAd = function () {
        this.rewardAd.destroy();
    };
    t.prototype.destoryInterstitial = function () {};
    t.prototype.viewData = function (t, e) {
        console.log("QTtAdDo ----------------- " + t, e);
    };
    t.prototype.preLoadPortalAd = function () {
        if (Date.now() - this.lastPortalTime > 5e3) {
            this.lastPortalTime = Date.now();
            this.firstPortalAd = !0;
            console.log("创建一个九宫广告");
            this.createNewPortalAd();
        }
    };
    t.prototype.destroyPortalAd = function () {
        null != this.portalAd && this.portalAd.destroy();
    };
    t.prototype.showPortalAd = function () {
        var t = this;
        if (null != this.portalAd && 1 == this.adSuccess[a.portal]) {
            console.log("展示九宫广告");
            this.portalAd
                .show()
                .then(function () {
                    console.log(t.idObj[a.portal], "show success");
                })
                .catch(function (e) {
                    console.log(t.idObj[a.portal], "show fail with:" + e.errCode + "," + e.errMsg);
                });
            this.adSuccess[a.portal] = !1;
            setTimeout(function () {
                t.createNewPortalAd();
            }, 5e3);
        } else {
            console.log("没九宫广告可以展示");
            this.createNewPortalAd();
        }
    };
    t.prototype.createVideoAd = function () {
        var t = this;
        if (this.idObj[a.rewardVedio])
            try {
                console.log("创建OPPO激励视频广告");
                this.rewardAd = n.default.Plat.createRewardedVideoAd({adUnitId: this.idObj[a.rewardVedio]});
                this.rewardAd.onLoad(function () {
                    console.log("加载激励广告成功");
                    t.adSuccess[a.rewardVedio] = !0;
                });
                this.rewardAd.onError(function (e) {
                    console.log("onError:" + JSON.stringify(e));
                    console.log("暂时没激励广告了");
                    t.adSuccess[a.rewardVedio] = !1;
                    t.rewardCallBack(!1);
                });
                this.rewardAd.onClose(function (e) {
                    if (null == e) {
                        t.rewardCallBack(!1);
                        console.log("返回激励出问题了");
                    } else {
                        console.log("点击了关闭激励广告", e);
                        if (e.isEnded) {
                            console.log("看完激励广告");
                            t.rewardCallBack(!0);
                        } else {
                            t.rewardCallBack(!1);
                            console.log("激励广告没看完");
                        }
                    }
                    t.adSuccess[a.rewardVedio] = !1;
                    t.createVideoAd();
                });
            } catch (t) {
                this.rewardCallBack(!1);
                this.adSuccess[a.rewardVedio] = !1;
                console.log("oppoRewardVideoAd error", t);
            }
        else console.log("视频广告参数没有配置");
    };
    t.prototype.createANativeAd = function () {
        var t = this;
        if (this.idObj[a.native]) {
            var e = function (t) {
                console.log(t);
            };
            if (null != this.nativeAd && null != this.nativeAdData && e) e(this.nativeAdData);
            else {
                this.nativeAd = n.default.Plat.createNativeAd({adUnitId: this.idObj[a.native]});
                this.nativeAd.onLoad(function (o) {
                    console.log("createNativeAd==>" + JSON.stringify(o));
                    if (o.adList && o.adList.length > 0) {
                        console.log("原生广告加载成功");
                        t.nativeAdId = o.adList[0].adId.toString();
                        t.nativeAdData = o.adList[0];
                        t.adSuccess[a.native] = !0;
                        e && e(o.adList[0]);
                    } else e && e(null);
                });
                this.nativeAd.onError(function (t) {
                    console.log("nativeAd:" + JSON.stringify(t));
                    e && e(null);
                });
                this.nativeAd.load();
            }
        } else console.log("原生广告参数没有配置");
    };
    t.prototype.onNativeAdClick = function () {
        if (this.nativeAd && null != this.nativeAdId) {
            this.nativeAd.reportAdClick({adId: this.nativeAdId});
            this.onNativeDestroy();
        }
    };
    t.prototype.onNativeDestroy = function () {
        console.log("onNativeDestroy:");
        if (this.nativeAd) {
            this.nativeAd.offLoad();
            this.nativeAd.offError();
            this.nativeAd.destroy();
            this.nativeAd = null;
            this.nativeAdData = null;
            console.log("原生广告销毁-" + location);
        }
    };
    t.prototype.createNewCustomAd = function () {
        var t = this;
        if (this.idObj[a.custom]) {
            if (this.customAd) {
                this.customAd.destroy();
                this.customAd = null;
            }
            null == this.customConfig && (this.customConfig = {top: 500, left: 0, width: 1200});
            console.log("创建的原生广告模板id", this.idObj[a.custom], this.customConfig);
            this.customAd = n.default.Plat.createCustomAd({adUnitId: this.idObj[a.custom], style: this.customConfig});
            this.customAd.onLoad(function () {
                t.adSuccess[a.custom] = !0;
                console.log("[原生模板广告] 广告加载成功");
            });
            this.customAd.onError(function (t) {
                console.log("错误监听：", JSON.stringify(t));
            });
            this.customAd.onShow(function () {
                console.log("customAd广告显示");
            });
            this.customAd.onHide(function () {
                n.default.isCloseCustomAd = !0;
                n.default.lastClickTime = Date.now();
                console.log("customAd广告隐藏");
            });
        } else console.log("原生模板广告参数没有配置");
    };
    t.prototype.createNewPortalAd = function () {
        var t = this;
        if (this.idObj[a.portal]) {
            if (this.portalAd) {
                this.portalAd.destroy();
                this.portalAd = null;
            }
            if (n.default.Plat.getSystemInfoSync().platformVersionCode < 1076) console.log("平台版本国小，无法创建");
            else {
                console.log("创建的九宫广告id", this.idObj[a.portal]);
                this.portalAd = n.default.Plat.createGamePortalAd({adUnitId: this.idObj[a.portal]});
                this.portalAd.onLoad(function () {
                    t.adSuccess[a.portal] = !0;
                    console.log("[九宫广告] 广告加载成功");
                });
                this.portalAd.onError(function (e) {
                    console.log("九宫广告加载错误监听：", t.idObj[a.portal], JSON.stringify(e));
                });
                this.portalAd.onClose(function () {
                    console.log("互推盒子九宫格广告关闭");
                });
                this.portalAd
                    .load()
                    .then(function () {
                        console.log("九宫广告加载");
                    })
                    .catch(function (t) {
                        console.log("load fail with:" + t.errCode + "," + t.errMsg);
                    });
            }
        } else console.log("九宫广告参数没有配置");
    };
    return t;
})();
o.default = r;
